using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for processOrderDetail
/// </summary>
public class processOrderDetail:DBConnectionTool
{
	public processOrderDetail() : base()
	{
		//
		// TODO: Add constructor logic here
		//
	}    


    public int insertOrderDetail(string OrderNumber, int Quantity, float Price,string OrderID, string ProductID)
    {
        OpenCn();        
        SqlCommand cmd = new SqlCommand("Insert Into OrderDetails(OrderNumber,Quantity,Price,OrderID,ProductID) Values(@OrderNumber,@Quantity,@Price,@OrderID,@ProductID)", cn);
        cmd.Parameters.Add(new SqlParameter("@OrderNumber", SqlDbType.Char, 16));
        cmd.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int));
        cmd.Parameters.Add(new SqlParameter("@Price", SqlDbType.Float));
        cmd.Parameters.Add(new SqlParameter("@OrderID", SqlDbType.Char, 16));
        cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Char, 7));
        cmd.Parameters["@OrderNumber"].Value = OrderNumber;
        cmd.Parameters["@Quantity"].Value = Quantity;
        cmd.Parameters["@Price"].Value = Price;
        cmd.Parameters["@OrderID"].Value = OrderID;
        cmd.Parameters["@ProductID"].Value = ProductID;        
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    public int updateOrderDetail(int Quantity, float Price, string OrderID, string ProductID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Update Orders(Quantity,Price,OrderID,ProductID) Values(@Quantity,@Price,@OrderID,@ProductID)", cn);
        
        cmd.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int));
        cmd.Parameters.Add(new SqlParameter("@Price", SqlDbType.Float));
        cmd.Parameters.Add(new SqlParameter("@OrderID", SqlDbType.Char, 8));
        cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Char, 7));
        
        cmd.Parameters["@Quantity"].Value = Quantity;
        cmd.Parameters["@Price"].Value = Price;
        cmd.Parameters["@OrderID"].Value = OrderID;
        cmd.Parameters["@ProductID"].Value = ProductID;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    public int deleteOrderDetail(string ProductID, string OrderID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("delete OrderDetails where ProductID = @ProductID and OrderID=@OrderID", cn);
        cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Char, 7));
        cmd.Parameters["@ProductID"].Value = ProductID;
        cmd.Parameters.Add(new SqlParameter("@OrderID", SqlDbType.Char, 8));
        cmd.Parameters["@OrderID"].Value = OrderID;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    

}
